package com.action;

import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.bean.Course;
import com.bean.Homework;
import com.bean.HomeworkPath;
import com.bean.Student;
import com.bean.Teacher;
import com.dao.CourseDao;
import com.dao.HomeworkDao;
import com.opensymphony.xwork2.ActionSupport;

public class HomeworkAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 8798334429669391609L;
	
	private List<Course> courseList;
	
	private List<Homework> homeworkList;
	
	private String courseName;
	
	private String homeworkName;
	
	private String homeworkContent;
	
	private HomeworkPath homeworkPath;
	
	private List<HomeworkPath> homeworkPathList;
	
	CourseDao cd = new CourseDao();
	
	HomeworkDao hd = new HomeworkDao();
	
	public String getListt(){
		courseList = cd.getCourseList();
		homeworkList = hd.getHomeworkList();
		//homeworkPathList = hd.homeworkPathList();
		return SUCCESS;
	}
	public String getLists(){
		courseList = cd.getCourseList();
		homeworkList = hd.getHomeworkList();
		homeworkPathList = hd.homeworkPathList();
		return SUCCESS;
	}
	
	public String addHomework(){
		Homework homework = new Homework();
		Teacher tea = (Teacher) ServletActionContext.getRequest().getSession().getAttribute("tea");
		try {
			courseName =new String(courseName.getBytes("iso-8859-1"),"UTF-8");
			homeworkName =new String(homeworkName.getBytes("iso-8859-1"),"UTF-8");
			homeworkContent =new String(homeworkContent.getBytes("iso-8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		homework.setCourseName(courseName);
		homework.setHomeworkContent(homeworkContent);
		homework.setHomeworkName(homeworkName);
		homework.setBelongTea(tea.getTeaUserID());
		hd.addHomework(homework);
		courseList = cd.getCourseList();
		homeworkList = hd.getHomeworkList();
		return SUCCESS;
	}
	
	public List<Course> getCourseList() {
		return courseList;
	}

	public void setCourseList(List<Course> courseList) {
		this.courseList = courseList;
	}

	public List<Homework> getHomeworkList() {
		return homeworkList;
	}

	public void setHomeworkList(List<Homework> homeworkList) {
		this.homeworkList = homeworkList;
	}

	public String getCourseName() {
		return courseName;
	}

	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}

	public String getHomeworkName() {
		return homeworkName;
	}

	public void setHomeworkName(String homeworkName) {
		this.homeworkName = homeworkName;
	}

	public String getHomeworkContent() {
		return homeworkContent;
	}

	public void setHomeworkContent(String homeworkContent) {
		this.homeworkContent = homeworkContent;
	}

	public void setHomeworkPath(HomeworkPath homeworkPath) {
		this.homeworkPath = homeworkPath;
	}

	public HomeworkPath getHomeworkPath() {
		return homeworkPath;
	}

	public void setHomeworkPathList(List<HomeworkPath> homeworkPathList) {
		this.homeworkPathList = homeworkPathList;
	}

	public List<HomeworkPath> getHomeworkPathList() {
		return homeworkPathList;
	}

	
}
